package com.wing.enterprise.sell.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.socket.sockjs.transport.TransportType;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 销售订单产品表
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sel_order_pro")
public class OrderPro extends BaseEntity<OrderPro> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Status implements IEnum<Integer> {

        /**
        * 待受理
        */
        pending(0,"待受理"),
        /**
        * 已受理
        */
        accepted(1,"已受理"),
        /**
        * 不受理
        */
        refuse(2,"不受理");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }

        @JsonCreator
        public static Status jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (Status item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }



    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 订单ID
     */
    private Long orderId;

    /**
     * 产品类型ID
     */
    private Long proTypeId;

    /**
     * 客户sku料号
     */
    private String customerSkuItem;

    /**
     * 客户sku名称
     */
    private String customerSkuName;

    /**
     * 客户规格码
     */
    private String customerSpecCode;

    /**
     * 产品单位ID
     */
    private Long proUnitId;

    /**
     * 是否需要包装
     */
    private Boolean whetherPack;

    /**
     * 包装说明
     */
    private String packExplain;

    /**
     * 需求数量
     */
    private Integer quantity;

    /**
     * 状态
     */
    private Status status;
    /**
     * 产品单位名称
     */
    @TableField(exist = false)
    private String proUnitName;
    /**
    * 状态描述
    */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }

    /**
     * 产品ID,无论新建还是关联内部,prodetail表ID
     */
    private Long relationProId;

    /**
     * 建议最低单价
     */
    private String suggestLowestPrice;

    /**
     * 建议单价
     */
    private String suggestPrice;

    /**
     * 优惠单价
     */
    private String discountPrice;
    /**
     * 报价说明
     */
    private String offerRemark;
    /**
    * 终审结果描述
    */
    @TableField(exist = false)
    private String finalResultDesc;

    /**
     * 附件列表
     */
    @TableField(exist = false)
    private List<OrderProEnclosure>  orderProEnclosureList= new ArrayList<OrderProEnclosure>();

    /**
     * 报价状态
     */
    public enum OfferStatus implements IEnum<Integer> {

        /**
         * 待报价
         */
        wait(0,"待报价"),
        /**
         * 报价中
         */
        running(1,"报价中"),
        /**
         * 报价已完成
         */
        finish(2,"报价已完成");

        private int code;
        private String desc;

        OfferStatus(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static OfferStatus jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (OfferStatus item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }
    /**
     * 报价状态
     */
    private OfferStatus offerStatus;

    /**
     * 报价状态描述
     */
    @TableField(exist = false)
    private String offerStatusDesc;

    public String getOfferStatusDesc() {
        return offerStatus == null ? null : offerStatus.getDesc();
    }

    /**
     * 描述
     */
    private String proRemark;
    /**
     * 最终报价
     */
    @TableField(exist = false)
    private BigDecimal offerMoney;
    /**
     * 产品类型
     */
    private String proTypeName;
    /**
     * 剩余数量
     */
    private Integer residueQuantity;

    /**
     * 物料id
     */
    private Long productDetailId;
}
